<?php
namespace App\Api;

use PhalApi\Api;
use App\Domain\Store as StoreDomain;
use App\Domain\Order as OrderDomain;


/**
 * 专场\商品\下单模块接口服务
 */
class Store extends Api {
    public function getRules() {
        return array(
            'storeList' => array(
                'page' => array('name' => 'page', 'type' => 'int', 'default' => 1, 'min' => 1, 'desc' => \PhalApi\T('page')),
                'limit' => array('name' => 'limit', 'type' => 'int', 'default' => 20, 'min' => 1, 'max' => 1000, 'desc' => \PhalApi\T('page limit')),
            ),
            'storeDetail' => array(
                'store_id' => array('name' => 'store_id', 'require' => true, 'desc' => '专场id'),
            ),
            'goodsList' => array(
                'page' => array('name' => 'page', 'type' => 'int', 'default' => 1, 'min' => 1, 'desc' => \PhalApi\T('page')),
                'limit' => array('name' => 'limit', 'type' => 'int', 'default' => 20, 'min' => 1, 'max' => 1000, 'desc' => \PhalApi\T('page limit')),
                'store_id' => array('name' => 'store_id', 'require' => true, 'desc' => '专场id'),
            ),
            'goodsDetail' => array(
                'goods_id' => array('name' => 'goods_id', 'require' => true, 'desc' => '商品id'),
            ),
            'confirmOrder' => array(
                'goods_id' => array('name' => 'goods_id', 'require' => true, 'desc' => '商品id'),
                'order_price' => array('name' => 'order_price', 'require' => true, 'desc' => '出价价格'),
            ),
        );
    }

    /**
     * 获取专场列表
     * @desc 获取专场列表
     * @return int total 总数
     * @return array items 数据列表
     * @return int items->store_id 专场id
     * @return string items->store_name 专场名称
     * @return string items->store_member_name  出品方
     * @return url items->store_avatar 出品方头像
     * @return string items->store_mobile 出品方联系方式
     * @return url items->store_imgs 专场展示图
     * @return int litems->ook_num 围观数
     * @return string items->status 专场状态 00预展中 10在拍 20已结拍
     * @return int items->order_num 出价数
     * @return int items->start_time 拍卖开始时间
     * @return int items->end_time 拍卖结束时间
     */
    public function storeList() {
        $domain = new StoreDomain();
        $where = array();
        //分页
        $page = $this->page? $this->page:1;
        $perpage = $this->limit?$this->limit:10;
        //要查询的字段
        $select="id as store_id,store_name,store_member_name,store_mobile,store_avatar,store_imgs,status,look_num,start_time,end_time";
        $order='resvered_field_01 ASC,is_top ASC,id DESC';
        $roles = $domain->storeList($where,$select,$order,$page,$perpage);
        return $roles;
    }

    /**
     * 获取专场详情
     * @desc 获取专场详情
     * @return int store_id 专场id
     * @return string store_name 专场名称
     * @return string store_member_name  出品方
     * @return url store_avatar 出品方头像
     * @return string store_mobile 出品方联系方式
     * @return url store_imgs 专场展示图
     * @return int look_num 围观数
     * @return string status 专场状态 00预展中 10在拍 20已结拍
     * @return int order_num 出价数
     * @return int goods_num 拍品数
     * @return int start_time 拍卖开始时间
     * @return int end_time 拍卖结束时间
     * @return string admin_name 主理人姓名
     * @return string desc 介绍
     */
    public function storeDetail() {
        $domain = new StoreDomain();
        $where = array();
        $where['id'] = $this->store_id;
        //要查询的字段
        $select="id as store_id,store_name,store_member_name,store_mobile,store_avatar,store_imgs,status,look_num,start_time,end_time,`desc`,delete_flag,admin_id";
        $roles = $domain->storeDetail($where,$select);
        return $roles;
    }

    /**
     * 获取专场下的商品列表
     * @desc 获取专场下的商品列表
     * @return int total 总数
     * @return array items 数据列表
     * @return int items->goods_id 商品id
     * @return string items->goods_name 商品名称
     * @return url items->goods_imgs 商品头图
     * @return string items->goods_no 商品编号
     * @return float items->price 商品基础价格(起拍价)
     * @return float litems->now_price 当前价格(落槌价)
     * @return int items->look_num 围观数
     * @return int items->level_num 出价数
     * @return int items->start_time 拍卖开始时间
     * @return int items->end_time 拍卖结束时间
     */
    public function goodsList() {
        $domain = new StoreDomain();
        $where = array();
        $where['store_id'] = $this->store_id;
        //分页
        $page = $this->page? $this->page:1;
        $perpage = $this->limit?$this->limit:10;
        //要查询的字段
        $select="id as goods_id,goods_imgs,goods_name,goods_no,look_num,level_num,now_price,price";
        $order='is_top ASC,id DESC';
        $roles = $domain->goodsList($where,$select,$order,$page,$perpage);
        return $roles;
    }

    /**
     * 获取商品详情
     * @desc 获取商品详情
     * @return int goods_id 商品id
     * @return string goods_name 商品名称
     * @return string goods_no 商品编号
     * @return float price 商品基础价格(起拍价)
     * @return float now_price 当前价格(落槌价)
     * @return string status 状态 00预展中 10在拍 20已结拍
     * @return float price_level 商品竞价阶梯
     * @return array goods_banner 商品轮播图
     * @return array goods_detail 商品详情图
     * @return string store_member_name  出品方姓名
     * @return url store_avatar 出品方头像
     * @return string admin_name 主理人姓名
     * @return url admin_avatar 主理人头像
     * @return int start_time 开始时间
     * @return int end_time 结束时间
     * @return array orderList 出价列表
     * @return int orderList->total 总数
     * @return array orderList->items 数据列表
     * @return string orderList->items->member_name 出价人姓名
     * @return url orderList->items->member_avatar 出价人头像
     * @return url orderList->items->member_mobile 出价人电话
     * @return float orderList->items->order_price 出价价格
     * @return float orderList->items->add_time 出价时间
     */
    public function goodsDetail() {
        $domain = new StoreDomain();
        $where = array();
        $where['id'] = $this->goods_id;
        //要查询的字段
        $select="id as goods_id,goods_name,goods_no,price,now_price,price_level,delete_flag,store_id";
        $roles = $domain->goodsDetail($where,$select);
        return $roles;
    }

    /**
     * 下单
     * @desc 下单
     */
    public function confirmOrder() {
        $domain = new OrderDomain();
        $roles = $domain->confirmOrder($this->goods_id,$this->order_price);
        return $roles;
    }
}
